var pageii = null;
var grid = null;

$(function () {
    grid = lyGrid({
        pagId: 'paging',
        l_column: [{
            colkey: "id",
            name: "id",
            hide:true
        },{
            colkey: 'title',
            name: '标题'
        }, {
            colkey: 'path',
            name: '图片地址'
        }/*, {
            colkey: 'content',
            name: '内容'
        }*/],
        jsonUrl: rootPath + '/app/tongue/findByPage.shtml',
        dymCol: true,
        checkbox: true,
        serNumber: true
    });
    $('#search').click('click', function () { // 绑定查询按扭
        var searchParams = $('#searchForm').serializeJson(); // 初始化传参数
        grid.setOptions({
            data: searchParams
        });
    });

    $("#addFun").click("click", function () {
        addFun();
    });
    $("#editFun").click("click", function () {
        editFun();
    });
    $("#delFun").click("click", function () {
        delFun();
    });
});

function editFun() {
    var cbox = grid.getSelectedCheckbox();
    if (cbox.length > 1 || cbox == "") {
        layer.msg("只能选中一个");
        return;
    }
    pageii = layer.open({
        title: "编辑",
        type: 2,
        area: ["800px", "90%"],
        content: rootPath + '/app/tongue/editUI.shtml?id=' + cbox
    });
}

function addFun() {
    pageii = layer.open({
        title: "新增",
        type: 2,
        area: ["800px", "90%"],
        content: rootPath + '/app/tongue/addUI.shtml'
    });
}

function delFun() {
    var cbox = grid.getSelectedCheckbox();
    if (cbox == "") {
        layer.msg("请选择删除项！！");
        return;
    }
    layer.confirm('是否删除？', function (index) {
        var url = rootPath + '/app/tongue/deleteEntity.shtml';
        var s = CommnUtil.ajax(url, {
            ids: cbox.join(",")
        }, "json");
        if (s == "success") {
            layer.msg('删除成功');
            grid.loadData();
        } else {
            layer.msg('删除失败');
        }
    });
}
function toggleStatus(id, status) {
    layer.confirm('是否执行该操作？', function (index) {
        if (status == 1) {
            status = 0;
        } else if (status == 0) {
            status = 1;
        }
        var url = rootPath + '/app/tongue/editStatus.shtml';
        var s = CommnUtil.ajax(url, {
            id: id,
            status: status
        }, "json");
        if (s == "success") {
            layer.msg('成功');
            grid.loadData();
        } else {
            layer.msg('失败');
        }
    });
}